Use of logic connectors
OR: ||
•The "or" operator is used by placing the "or" symbol, ||, in between two boolean values.
//suppose that Graham is tired
bool grahamIsTired = true;
//but Graham doesn't have to wake up early
bool grahamMustWakeUpEarly = false;
//will Graham go to sleep now?
bool bedTime = grahamIsTired || grahamMustWakeUpEarly;
What does this code do?
This example is very similar to the example involving Fran (see previous slide with AND operator), except notice the key difference: whether or not Graham goes to sleep is determined differently. Graham will go to sleep if he is tired or if he needs to wake up early. Whereas Fran would go to sleep only if both conditions were true, Graham will go to sleep if either condition (or both) is true. Therefore, the value of bedTime is true.